package org.learn.intermediate.com.exercise;

public class Exercise04 {
    public static void main(String[] args) {
        //判断两个Person02对象各个属性内容是否一样；一样返回真，否则返回假
        Person02 person02 = new Person02("胜红" , 10, '男');
        Person02 person03 = new Person02("胜红" , 10, '男');

        System.out.println(person02.equals(person03));
        //object默认比较地址。需要重写equals方法

    }
}
class Person02 {
    private String name;
    private Integer age;
    private char gender;

//重写equals方法
    public boolean equals(Object obj) {
        if(this == obj) {
            return true;
        }
        //类型判断
        if(obj instanceof Person02){
            //判断是否一个运行类型；
            //向下转型
            Person02 p = (Person02)obj;
            return this.name.equals(name) && this.age ==p.age && this.gender == p.gender;
        }
        return false;
    }
    //同理，重写toString   快捷键alt + insert，当然程序员也可以自己设置good



    @Override
    public String toString() {
        return "Person02{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                '}';
    }
    //



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public Person02(String name, int age, char gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;


    }
}
